/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * MainFrame.java
 *
 * Created on 4 juil. 2011, 19:24:03
 */
package app.views;
import app.App;
import app.core.IncludedPan;
import java.awt.Desktop;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.net.URI;
import javax.swing.UIManager;

/**
 *
 * @author Ghost
 */
public class MainFrame extends javax.swing.JFrame {
        /** Creates new form MainFrame */
    public MainFrame() {
        initComponents();
        
        //Centering it on screen
        Toolkit kit = this.getToolkit();
        Dimension dim = kit.getScreenSize();
        int height, width, x, y;
        width = 500;
        height = 400;
        x = (dim.width - width) / 2;
        y = (dim.height - height) / 2;

        this.setBounds(x, y, width, height);
        
    }

    @Override
    public void setVisible(boolean b) {
        super.setVisible(b);
        this.mainContent.showPan(0);
    }
    
    public void addPanel(IncludedPan pan){
        this.mainContent.addPanel(pan);
    }
    

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        mainContent = new app.core.IncludePanel(this);
        mainMenu = new javax.swing.JMenuBar();
        mFichier = new javax.swing.JMenu();
        miConfig = new javax.swing.JMenuItem();
        miQuitter = new javax.swing.JMenuItem();
        mHelp = new javax.swing.JMenu();
        miBug = new javax.swing.JMenuItem();
        miAPropos = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("BornToStock");
        setIconImage(app.App.createImage("resources/logo.png"));
        setName("Form"); // NOI18N

        mainContent.setName("mainContent"); // NOI18N

        mainMenu.setName("mainMenu"); // NOI18N

        mFichier.setText("Fichier");
        mFichier.setName("mFichier"); // NOI18N

        miConfig.setText("Config...");
        miConfig.setName("miConfig"); // NOI18N
        miConfig.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                miConfigActionPerformed(evt);
            }
        });
        mFichier.add(miConfig);

        miQuitter.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_Q, java.awt.event.InputEvent.CTRL_MASK));
        miQuitter.setText("Quitter");
        miQuitter.setName("miQuitter"); // NOI18N
        miQuitter.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                miQuitterActionPerformed(evt);
            }
        });
        mFichier.add(miQuitter);

        mainMenu.add(mFichier);

        mHelp.setText("?");
        mHelp.setName("mHelp"); // NOI18N

        miBug.setText("Bug trouvé!");
        miBug.setName("miBug"); // NOI18N
        miBug.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                miBugActionPerformed(evt);
            }
        });
        mHelp.add(miBug);

        miAPropos.setText("A propos...");
        miAPropos.setName("miAPropos"); // NOI18N
        miAPropos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                miAProposActionPerformed(evt);
            }
        });
        mHelp.add(miAPropos);

        mainMenu.add(mHelp);

        setJMenuBar(mainMenu);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(mainContent, javax.swing.GroupLayout.DEFAULT_SIZE, 382, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(mainContent, javax.swing.GroupLayout.DEFAULT_SIZE, 268, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void miAProposActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miAProposActionPerformed
        new Thread(new Runnable() {
            public void run() {
                new APropos();
            }
        }).start();
    }//GEN-LAST:event_miAProposActionPerformed

    private void miConfigActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miConfigActionPerformed
        new ConfigDial(this, true);
    }//GEN-LAST:event_miConfigActionPerformed

    private void miQuitterActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miQuitterActionPerformed
        System.exit(0);
    }//GEN-LAST:event_miQuitterActionPerformed

    private void miBugActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miBugActionPerformed
        try{
            Desktop.getDesktop().browse(new URI("http://code.google.com/p/borntostock/issues/entry"));
        } catch(Exception e){}
    }//GEN-LAST:event_miBugActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new MainFrame().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenu mFichier;
    private javax.swing.JMenu mHelp;
    private app.core.IncludePanel mainContent;
    private javax.swing.JMenuBar mainMenu;
    private javax.swing.JMenuItem miAPropos;
    private javax.swing.JMenuItem miBug;
    private javax.swing.JMenuItem miConfig;
    private javax.swing.JMenuItem miQuitter;
    // End of variables declaration//GEN-END:variables
}
